/*
 * Copyright 2006 Brian Watkins
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */


package bw.util;

import java.util.*;

public class Config
{
    private static Config _instance = null;
    private static Object _lock = new Object();

    private Hashtable _properties = new Hashtable();

    public static String getProperty ( String name )
    {
        Config config = Config.getInstance();
        return config.getProperty( name );
    }

    public static boolean isPropertyTrue ( String name )
    {
        Config config = Config.getInstance();
        return "true".equalsIgnoreCase( config.getValue( name ) );
    }

    public static void setProperty ( String name, boolean value )
    {
        Config.setProperty( name, String.valueOf( value ) );
    }

    public static void setProperty ( String name, String value )
    {
        Config config = Config.getInstance();
        config.setValue( name, value );
    }

    public static Config getInstance ()
    {
        if ( _instance == null )
        {
            synchronized ( _lock )
            {
                if ( _instance == null ) 
                {
                    _instance = new Config();
                }
            }
        }
        
        return _instance;
    }
    
    private Config ()
    {
        //nothing
    }
    
    private String getValue ( String name )
    {
        return (String) _properties.get( name );
    }

    private void setValue ( String name, String value )
    {
        _properties.put( name, value );
    }
    
}